#ifndef NET_UDP_CONNECTION_H
#define NET_UDP_CONNECTION_H

#include <boost/asio.hpp>

using boost::asio::ip::udp;

#define MPN_UDP_SERVER_ID			254
#define MPN_UDP_NO_ID				255
/*! Size of packet buffer arrays */
#define MPN_UDP_PKT_BUFFER_MAX		1024

/* -127 to 127 */

/*! Special byte to then check for a command */
#define MPN_UDP_PKT_SPECIAL_BYTE	127
/*! Special command representing the start of a packet */
#define MPN_UDP_PKT_START			124
/*! Special command representing the end of the data stream */
#define MPN_UDP_PKT_END_DATA		126
#define MPN_UDP_PKT_HANDSHAKE		125


namespace mp_net
{
	struct UdpConnection
	{
		UdpConnection():m_id(MPN_UDP_NO_ID),m_endpoint(),
			m_inBufferReady(false),m_outBufferReady(false),
			m_inBufferIndex(0),m_outBufferIndex(0){
			m_inBuffer[0] = m_outBuffer[0] = MPN_UDP_PKT_SPECIAL_BYTE;
			m_inBuffer[1] = m_outBuffer[1] = MPN_UDP_PKT_END_DATA;
		}

		unsigned char	m_id;	//0-255
		udp::endpoint	m_endpoint;

		char			m_inBuffer[MPN_UDP_PKT_BUFFER_MAX];
		unsigned int	m_inBufferIndex;
		bool			m_inBufferReady;
		char			m_outBuffer[MPN_UDP_PKT_BUFFER_MAX];
		unsigned int	m_outBufferIndex;
		bool			m_outBufferReady;

		inline bool operator==(const UdpConnection& lhs)
			{ return m_id == lhs.m_id; }
		inline bool operator!=(const UdpConnection& lhs)
			{ return m_id != lhs.m_id; }
		inline bool operator>=(const UdpConnection& lhs)
			{ return m_id >= lhs.m_id; }
		inline bool operator>(const UdpConnection& lhs)
			{ return m_id > lhs.m_id; }
		inline bool operator<=(const UdpConnection& lhs)
			{ return m_id <= lhs.m_id; }
		inline bool operator<(const UdpConnection& lhs)
			{ return m_id < lhs.m_id; }

	};
}
#endif